<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<title>提交新运单</title>
		<link rel="stylesheet" type="text/css" href="btn_class.css" />
		<link rel="stylesheet" type="text/css"
			href="ext-2.2/resources/css/ext-all.css" />
		<link rel="stylesheet" type="text/css"
			href="ext-2.2/ext-2.2/style.css" />
		<link rel="stylesheet" type="text/css"
			href="ext-2.2/ext-2.2/desktop.css" />
		<link rel="stylesheet" type="text/css"
			href="ext-2.2/ext-2.2/ext-patch.css" />

		<script type="text/javascript" src="ext-2.2/adapter/ext/ext-base.js"></script>
		<script type="text/javascript" src="ext-2.2/ext-all.js"></script>
		<script type="text/javascript" src="js/util.js"></script>

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

		<script type="text/javascript">
		<%String uId = (String) session.getAttribute("Uid");
			if (uId == null || uId.equals("null")) {%>
			window.parent.location.href = 'index.jsp';
		<%}%>
		function update_op(flag){
			if(flag=='A'){
				document.getElementById("wbTogetherSvc").disabled =  "disabled";
				document.getElementById("wbTogetherSvc").checked =  "";
				document.getElementById("wbSplitSvc").disabled =  "disabled";
				document.getElementById("wbSplitSvc").checked =  "";
				document.getElementById("wbSplitNum").disabled =  "disabled";
			}
			if(flag=='B'){
				document.getElementById("wbTogetherSvc").disabled = "";
				document.getElementById("wbSplitSvc").disabled =  "";
				//document.getElementById("wbSplitNum").disabled =  "";
			}
			if(flag=='C'){
				var disFlag = document.getElementById("wbSplitNum").disabled;
				
				if(!disFlag)
				{
					document.getElementById("wbSplitNum").disabled =  "disabled";
				}else			
				{
					document.getElementById("wbSplitNum").disabled =  "";
				}
			}
		}
		//简单的根据class找元素
		function getByClass(oParent,sClass){
		     var aEle=oParent.getElementsByTagName('tr');
 		     var aResult=[];
   		     var i=0;
		     for(i=0; i<aEle.length; i++){
	          if(aEle[i].className==sClass){aResult.push(aEle[i])}
		     }
		     return aResult;
		}
		
		function showEnterWaybillListDiv(){
			var wbWarehouse = document.getElementById("wbWarehouse").value;
			var enterWaybillListDiv = document.getElementById("enterWaybillListDiv");
			if(wbWarehouse == ""){
				enterWaybillListDiv.style.display = "none";
				var inputs = document.getElementsByName("wbChoseEnterWaybill");
				for(var i=0;i<inputs.length;i++){
					inputs[i].checked = false;
				}
			}else{
				enterWaybillListDiv.style.display = "block";
				var aEle=enterWaybillListDiv.getElementsByTagName('tr');
				//选择CA的 class为CA的显示
 		     	var aResult=[];
 		     	//不选择CA的隐藏
 		     	var bResult =[];
   		     	var j=0;
		     	for(j=0; j<aEle.length; j++){
	          		if(aEle[j].className!="" && aEle[j].className==wbWarehouse){aResult.push(aEle[j])}
	          		else if(aEle[j].className!="" && aEle[j].className!=wbWarehouse){bResult.push(aEle[j]); }
		     	}
				for(var i=0;i<aResult.length;i++){
					aResult[i].style.display="block";
				}
				for(var i=0;i<bResult.length;i++){
					bResult[i].childNodes[0].childNodes[0].checked = false;
					bResult[i].style.display="none";
				}
				//根据选择的仓库,来选择性的显示中国的口岸
				if(wbWarehouse == "CA")
				{
					removeAll("wbKouAn");
					addOption("wbKouAn","成都","BJ");
					addOption("wbKouAn","天津","TJ");
					addOption("wbKouAn","上海(经济)","SHJJ");
					addOption("wbKouAn","上海普货(包税)","SHBS");
					addOption("wbKouAn","上海包税电子产品","SHBSDZ");
					addOption("wbKouAn","上海特殊类电子产品(手机、电脑)","SHPC");
					addOption("wbKouAn","上海其他","SHQT");		
					chageTip();					
				}
				if(wbWarehouse == "OR")
				{
					removeAll("wbKouAn");
					addOption("wbKouAn","成都","BJ");
					addOption("wbKouAn","天津","TJ");
					addOption("wbKouAn","上海(经济)","SHJJ");
					addOption("wbKouAn","上海普货(包税)","SHBS");
					addOption("wbKouAn","上海包税电子产品","SHBSDZ");
					addOption("wbKouAn","上海特殊类电子产品(手机、电脑)","SHPC");
					addOption("wbKouAn","上海其他","SHQT");
					chageTip();				
				}
				if(wbWarehouse == "NK")
				{
					removeAll("wbKouAn");
					addOption("wbKouAn","福州","FZ");		
					chageTip();					
				}
			}
		}
	
		
			
		function customerSubmitWaybill(){
			if(document.getElementById("wbWarehouse").value==""){
				alert("请选择仓库！");
				return;
			}
			//填写货物说明
			if(document.getElementById("wbGoodsDesc").value==""){
				alert("请填写货物说明！");
				return;
			}
			
			//请填写申报价值
			if(document.getElementById("wbApplyValue").value==""){
				alert("请填写申报价值！");
				return;
			}
			//下面是javascript获取单选框
			var sel = 0; 
			for (var i = 0; i < document.getElementsByName("wbOperateRequireType").length; i++) 
			　{ 
			  　　if(document.getElementsByName("wbOperateRequireType")[i].checked) {
			   　　　　sel = document.getElementsByName("wbOperateRequireType")[i].value; }
			　} 
			//ups选择的情况
			var choseUpsLen=0;
			var ups = document.getElementsByName("wbChoseEnterWaybill");
			for(var i=0;i<ups.length;i++){
				if(ups[i].checked){
					choseUpsLen++;
				}
			}
			//收获地址选择的情况
			var choseAddressLen=0;
			var addr = document.getElementsByName("wbAddressList");
			for(var i=0;i<addr.length;i++){
				if(addr[i].checked){
					choseAddressLen++;
				}
			}
			
			//如果是基本服务,只可以选择一个运单号和一个地址
			if(sel==0){
				if(choseUpsLen!=1){
					alert("基本服务(原箱转发)中,只可以选择一个运单号!");
					return;
				}
					if(choseAddressLen!=1){
					alert("基本服务(原箱转发)中,只可以选择一个收获地址!");
					return;
				}
			}
			if(sel==1 && !document.getElementById("wbTogetherSvc").checked && !document.getElementById("wbSplitSvc").checked){
					alert("高级服务需要选择合箱或分箱!");
					return;
			}
			//如果是高级服务,单独点了合箱
			if(sel==1 && document.getElementById("wbTogetherSvc").checked && !document.getElementById("wbSplitSvc").checked){
				if(choseUpsLen<2){
					alert("合箱操作时必须选择至少2个运单号!");
					return;
				}
				if(choseAddressLen!=1){
					alert("合箱操作时只可以选择一个收获地址!");
					return;
				}
			}
				//如果是高级服务,单独点了分箱
			if(sel==1 && document.getElementById("wbSplitSvc").checked && !document.getElementById("wbTogetherSvc").checked){
				if(choseUpsLen!=1){
					alert("分箱操作时只能选一个运单号!");
					return;
				}
				if(document.getElementById("wbSplitNum").value!=choseAddressLen){
					alert("分箱操作时分箱数必须和收获地址数目相同!");
					return;
				}
			}
			//如果是高级服务，并且是混合分箱
			if(sel==1 && document.getElementById("wbSplitSvc").checked && document.getElementById("wbTogetherSvc").checked){
				if(choseUpsLen<2){
					alert("混合分箱时,至少选择两个运单号!");
					return;
				}
				if(document.getElementById("wbSplitNum").value!=choseAddressLen){
					alert("混合分箱操作时分箱数必须和收获地址数目相同!");
					return;
				}
			}
			var f = document.forms["customerSubmitWaybillForm"];
			f.action = "waybill!customerSubmitNewWaybill.do";
			f.submit();
			//alert("订单提交成功！");
		}
		function setIntegral(){
			Ext.Ajax.request({ 
                   //请求地址 
                   url: 'integral!getIntegralPoint.do?Uid=<%=session.getAttribute("Uid")%>', 
                   //成功时回调 
                   success: function(response, options) { 
                      //获取响应的json字符串 
                      
                     var responseArray = Ext.util.JSON.decode(response.responseText);    
                          if(responseArray.success==true){ 
                          	var point =  responseArray.point;
                          	if(point<=0 || point == undefined){
                          		document.getElementById("wbIsIntegral").disabled = "disabled";
                          	}
                         	document.getElementById("integralNum").innerHTML = point;
                          } 
                	  } 
          	}); 
		}

		function chageTip(){
			var v = document.getElementById("wbKouAn").value;
			var w = document.getElementById("wbWarehouse").value;
			var tip = document.getElementById("messageId");
			if(v == "BJ") tip.innerHTML = "4.5美金/磅";
			if(v == "GZ") tip.innerHTML = "5美金/磅";
			if(v == "GZBS") tip.innerHTML = "6美金/磅";
			if(v == "SHPC")
			{
				 tip.innerHTML = "上海特殊类电子产品,高档手机、手提电脑、新苹果、ipad,价格6美金/磅,首重10,续重6";
				 document.getElementById("integral").style.display  = 'none';
			}else if(v == "SHBS")
			{
				 tip.innerHTML = "上海普货包税线,价格6美金/磅";
				 document.getElementById("integral").style.display  = 'none';
			}else if( v=="SHBSDZ" ){
				tip.innerHTML = "上海电子化妆品等,首重8,续重6";
				 document.getElementById("integral").style.display  = 'none';
			}else if( v=="SHJJ" ){
				tip.innerHTML = "上海经济线，4.5美金1磅，无首重";
				 document.getElementById("integral").style.display  = 'none';
			}else if( v=="SHQT" ){
				tip.innerHTML = "上海其他类,钻石、项链等,首重12,续重10";
				 document.getElementById("integral").style.display  = 'none';
			}
			else if(v == "FZ")
			{
				tip.innerHTML = "5美金/磅";
				document.getElementById("integral").style.display  = 'none';
			}else if(v == "TJ"){
				tip.innerHTML = "首重5.5美金/磅,续重4.5美金/磅,注意:不能发电子产品";
				document.getElementById("integral").style.display  = 'none';
			}
			else{
				document.getElementById("integral").style.display  = '';
			}
		}
		window.onload = function(){
			if("<%=request.getAttribute("accoutFlag")%>"=="noEnough")
			{
				var money = "<%=request.getAttribute("needMoney")%>"
				//window.location.href = "/create_direct_pay_by_user_jsp_utf8/index.jsp";
				window.location.href = "/waybill!queryAdressListAndEenterWaybillList.do?type=common";
				alert("对不起，您的账户余额不足！请先充值，你的所有订单预计金额为: "+money+" RMB");
				return;
			}
			if( "<%=request.getAttribute("customerSubmitFlag")%>"=="SUCCESS")
			{
				alert("订单提交成功！");
			}
			window.parent.left.location.reload(); 
			setIntegral();
		}
	</script>
	<style type="text/css">
		input
		{
			padding-bottom : 0px;
			margin : 0px;
			padding-left : 0px;
			padding-right : 0px;
			font-family : "宋体", Arial, Helvetica, sans-serif;
			font-size : 12px;
			padding-top : 0px;
			height : 90px;
		}
		.inputradio
		{
			padding-bottom : 0px;
			margin : 0px;
			padding-left : 0px;
			padding-right : 0px;
			font-family : "宋体", Arial, Helvetica, sans-serif;
			font-size : 12px;
			padding-top : 0px;
			height : 12px;
		}
		.btnSubmit
		{
			padding-bottom : 0px;
			margin : 0px;
			padding-left : 0px;
			padding-right : 0px;
			font-family : "宋体", Arial, Helvetica, sans-serif;
			font-size : 12px;
			padding-top : 0px;
			height : 18px;
		}
		div
		{
			padding-bottom : 0px;
			margin : 0px;
			padding-left : 0px;
			padding-right : 0px;
			font-family : "宋体", Arial, Helvetica, sans-serif;
			font-size : 12px;
			padding-top : 0px;
			
		}
		.right_center
		{
			background : white;
			padding-bottom: 50px;
			padding-left: 30px;
			width : 100%;
			padding-right: 0px;
			padding-top: 28px;
		}
		.wenzi
		{
			text-align : right;
			line-hight :20 px;
			width :102px;
			padding-right :10px;
			float : left;
			height :20 px;
		}
		.wenzi2
		{
			text-align : right;
			line-hight :18 px;
			width :100px;
			float : left;
			height :75 px;
		}
		
		.bd1
		{
			width : 200px;
			float : left;
			height : 20px;
		}
		.wwhh
		{
			padding-bottom : 10px;
			line-height : 14px;
			padding-left : 110px;
			width : 1000px;
			padding-right : 0px;
			color : #a9a9a9;
			padding-top : 0px;
		}
		.pd1
		{
			padding-left : 10px;
		}
	
		.bd3
		{
			width : 13px;
			height : 13px;
		}
		.bd4
		{
			margin : 0px 5px;
			width : 40px;
			height : 15px;
		}
		.bd5
		{
			width : 80px;
			height : 15px;
		}
		.bd6
		{
			width : 582px;
			height : 88px;
		}
		.pd5
		{
			line-height : 18px;
			padding-left : 176px;
			padding-top : 10px;
		}
		.tdCss
		{
			padding-bottom:0px;
			margin:0px;
			padding-left : 0px;
			padding-right:0px;
			font-family: "宋体", Arial, Helvetica, sans-serif;
			font-size : 12px;
			padding-top : 0px;
		}
	</style>
	</head>


<body class="ext-ie ext-ie6 ext-border-box " id="ext-gen6">
<div class="x-panel x-panel-noborder x-form-label-right" id="ext-comp-1001" style="width: 100%;">
	<div class="x-panel-header x-panel-header-noborder x-unselectable" id="ext-gen8" style="mozuserselect: none; khtmluserselect: none;" unselectable="on">
		<span class="x-panel-header-text" id="ext-gen21">提交新运单</span>
	</div>
	 <form name="customerSubmitWaybillForm" method="post">
		<div class="right_center">
			<div style="height:26px">
				<div class="wenzi">选择仓库</div>
				<select name="wbWarehouse" id="wbWarehouse" class="bd1" onchange ="showEnterWaybillListDiv();">
					<option value="" >请选择货物所在仓库</option>
					<option value="CA" >CA 地址</option>
					<option value="OR" >OR 地址</option>
					<option value="NK" >New York 地址</option>
				</select>
			</div>
			  <p class="wwhh"><font color="#ff0000">选择货物所在仓库，一个运单只能选择一个仓库内货物提交！</font></p>
			 <div style="line-height : 26px;padding-left : 48px; display : none" id="enterWaybillListDiv">
				<table width="700" border="0" cellSpacing="1" cellPadding="1"  style="border-collapse:collapse;" >
				<s:iterator id="enterWaybill" value="enterWaybillList">
				<tr class="<s:property value="#enterWaybill.wbArea"/>" style="display:none;">
					<td width="10" align="left">
						<input name="wbChoseEnterWaybill" class="bd3" type="checkbox" valign="top" value="<s:property value="#enterWaybill.wbId"/>" />
					</td>
					<td width="200" class="tdCss" align="left">
						<s:property value="#enterWaybill.wbUps" />&nbsp;&nbsp;&nbsp;<font color="#ff0000">[<s:property value="#enterWaybill.wbEnterWeight" />&nbsp;LBS]</font>
					</td>
				<tr>
				</s:iterator>
				</table>
				
			</div>
			<br/>
			<div class="hn">
				<div class="wenzi">货物说明：</div>
				<textarea name="wbGoodsDesc" id="wbGoodsDesc" class="bd6" rows="5" cols="50"></textarea>
				<p class="wwhh"><font color="#ff0000">请如实填写，如海关抽查到描述不符，可能被没收!</font></p>
				<p class="wwhh"><font color="#ff0000">如：鞋子5双、剃须刀2个、电动玩具1个</font></p>
			</div>
			<div style="height:26px">
				<div class="wenzi">申报价值：</div>
				<input name="wbApplyValue" class="bd1" type="text" size="18" onkeyup="value=value.replace(/[^\d{1,}\.\d{1,}|\d{1,}]/g,'')"/>
				<span class="pd1">美金</span>
				<span class="pd1">需要购买保险（3%申报价值）</span>
				<input name="wbInsuranceFlag" class="bd3" type="checkbox" value="Y"/>
			</div>
				<div style="height:26px">
				<div class="wenzi"><font style="color:red">选择口岸：</font></div>
				<select name="wbKouAn" id="wbKouAn" class="bd1" onchange="chageTip()">
					<!-- <option value="BJ" >北京</option> -->
					<option value="BJ" >成都</option>
					<!-- 
						<option value="GZ" >广州</option>
						<option value="GZBS" >广州(包税)</option>
						 -->
						<option value="SHBS" >上海(包税)</option>
						<option value="SHBSDZ" >上海包税电子产品</option>
					<!--<option value="TJ" >天津</option>-->
					<!-- <option value="CQ" >重庆</option> -->
				</select>
				<span class="pd1" id="messageId" style="color:red"></span>
			</div>
			
			<div class="hn">
				<div class="wenzi2">操作要求：</div>
				<div style="height:26px">
					<label style="height:30px">
						<input name="wbOperateRequireType" id="wbOperateRequireType1" type="radio" checked="checked" value="0" class="inputradio" onclick="update_op('A');"/>
						基本服务 原箱转运;
					</label>
				</div>
				<div style="height:26px">
						<input name="wbOperateRequireType" id="wbOperateRequireType2" type="radio" value="1" class="inputradio" onclick="update_op('B');" />
						高级服务 A. 合箱服务
						<input name="wbTogetherSvc" disabled="disabled" id="wbTogetherSvc"  type="checkbox"  value="1" class="inputradio"/>
						B. 分箱服务
						<input name="wbSplitSvc" disabled="disabled" id="wbSplitSvc"  type="checkbox" value="1" class="inputradio" onclick="update_op('C')"/>
						分箱数量
						<select name="wbSplitNum" disabled="disabled"  id="wbSplitNum">
							<option value="2" >2</option>
							<option value="3" >3</option>
							<option value="4" >4</option>
							<option value="5" >5</option>
							<option value="6" >6</option>
							<option value="7" >7</option>
							<option value="8" >8</option>
							<option value="9" >9</option>
							<option value="10" >10</option>
							<option value="11" >11</option>
							<option value="12" >12</option>
							<option value="13" >13</option>
							<option value="14" >14</option>
							<option value="15" >15</option>
							<option value="16" >16</option>
							<option value="17" >17</option>
							<option value="18" >18</option>
							<option value="19" >19</option>
							<option value="20" >20</option>
							<option value="21" >21</option>
							<option value="22" >22</option>
							<option value="23" >23</option>
							<option value="24" >24</option>
							<option value="25" >25</option>
						</select>
				</div>
			</div>
			<div class="pd5">
			如无特殊需求，我们将按照经验为您分/合箱；
			</div>
			<div style="height:26px">
				<div class="wenzi">包装要求：</div>
				<div style="height:26px">
					<label style="height:30px">
						取出发票
						<input name="wbPackqcfp"  type="checkbox"  value="1" class="inputradio"/>
						加急处理
						<input name="wbPackjjcl"  type="checkbox"  value="1" class="inputradio"/>
						内件加固
						<input name="wbPacknjjg"  type="checkbox"  value="1" class="inputradio"/>
						更换外箱
						<input name="wbPackghwx"  type="checkbox"  value="1" class="inputradio"/>
						加套外箱
						<input name="wbPackjtwx"  type="checkbox"  value="1" class="inputradio"/>
						去除内件
						<input name="wbPackqcnj"  type="checkbox"  value="1" class="inputradio"/>
						原箱转发
						<input name="wbPackyxzy"  type="checkbox"  value="1" class="inputradio"/>
						指定物品分箱
						<input name="wbPackzdwpfx"  type="checkbox"  value="1" class="inputradio"/>
					</label>
				</div>
			</div>
			<div style="height:26px;display:''" id="integral">
				<div class="wenzi">用积分抵扣：</div>
				<input name="wbIsIntegral" class="bd3" id="wbIsIntegral" type="checkbox" value="Y" />
				<span class="pd1">我目前的积分：<span style="color:red" id="integralNum"></span></span>
			</div>
			<div class="hn">
				<div class="wenzi">备注说明：</div>
				<textarea name="wbNote" class="bd6" rows="5" cols="50"></textarea>
			</div>
				  
			
			<div style="line-height:26px;padding-left:48px;height:26px;padding-top:5px;">
			请填写运单内容并核对，详尽正确的货物描述信息是准确操作的重要保障！
			</div>
			<div style="height:40px"></div>
			
			<div style="line-height : 26px;padding-left : 48px;">
				<table width="700" border="1" cellSpacing="1" cellPadding="0"  style="border-collapse:collapse;" >
				<tr>
					<td colspan="4" align="center"><font color="#ff0000">收货地址选择</font></td>
				</tr>
				<s:iterator id="addr" value="addressList">
				<tr>
					<td width="40" align="center">
						<input name="wbAddressList" class="bd3" type="checkbox" valign="top" value="<s:property value="#addr.PUaddrId"/>" />
					</td>
					<td width="100" class="tdCss" align="center">
						<s:property value="#addr.PUname" />	
					</td>
					<td width="100" class="tdCss">
						<s:property value="#addr.PUphoneNum" />	
					</td>
					<td width="*"  class="tdCss">
						<s:property value="#addr.PUarea" />---<s:property value="#addr.PUaddress" />
					</td>
				<tr>
				</s:iterator>
				</table>
				
			</div>
			
			
			<div style="line-height:10px;padding-left:50px;padding-top:18px;" >			
				<input type="button" value="提交运单" class="btnSubmit" onclick="customerSubmitWaybill()" />
			</div>
			
		</div>
	</form>
</div>
</body>

</html>

